package com.boc.langxiang.util;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.boc.langxiang.R;
import com.boc.langxiang.ui.view.MyCustomAlertDialog;
import com.boc.langxiang.ui.view.OutProjectDialog;


public class DialogUtil {

    public static Dialog createProgressDialog(Context mContext) {
        return createProgressDialog(mContext, null);
    }

    public static Dialog createProgressDialog(Context mContext, String content) {
        Dialog dialog = new Dialog(mContext, R.style.MyDialogStyle);
        View v = LayoutInflater.from(mContext).inflate(R.layout.view_dialog_progress, null);
        if (!TextUtils.isEmpty(content)) {
            ((TextView) v.findViewById(R.id.content)).setText(content);
        }
        dialog.setContentView(v);
        return dialog;
    }


    /**
     * 弹出框点击事件
     */
    public static interface OnCustomAlertDialogClickListener {
        public void onPositiveButtonClick(MyCustomAlertDialog dialog);

        public void onNegativeButtonClick(MyCustomAlertDialog dialog);
    }

    public static interface OnOutProjectDialogClickListener {
        public void onPositiveButtonClick(OutProjectDialog dialog);

        public void onNegativeButtonClick(OutProjectDialog dialog);
    }

    /**
     * 弹出框  底部按钮默认  左边取消  右边确认
     *
     * @param mContext
     * @param content
     * @param listener
     * @return
     */
    public static MyCustomAlertDialog createCustomAlertDialog(Context mContext, String title, String content, OnCustomAlertDialogClickListener listener) {
        return createCustomAlertDialog(mContext, title, content, "取消", "确定", listener);
    }

    /**
     * 弹出框  底部可自定义  不要哪个就不传哪个  比如不要positive  positive就传Null
     *
     * @param mContext
     * @param content
     * @param negative
     * @param positive
     * @param listener
     * @return
     */
    public static MyCustomAlertDialog createCustomAlertDialog(Context mContext, String title, String content, String negative, String positive, OnCustomAlertDialogClickListener listener) {
        MyCustomAlertDialog.Builder buider = new MyCustomAlertDialog.Builder(mContext);
        if (!TextUtils.isEmpty(title)) {
            buider.setTitle(title);
        }
        if (!TextUtils.isEmpty(content)) {
            buider.setMessage(content);
        }
        if (!TextUtils.isEmpty(negative)) {
            buider.setNegative(negative);
        }
        if (!TextUtils.isEmpty(positive)) {
            buider.setPositive(positive);
        }
        buider.setOnCustomAlertDialogClickListener(listener);
        return buider.create();
    }


    public static MyCustomAlertDialog createCustomAlertDialog(Context mContext, String title, String content, String negative, String positive,int negativeColor, OnCustomAlertDialogClickListener listener) {
        MyCustomAlertDialog.Builder buider = new MyCustomAlertDialog.Builder(mContext);
        if (!TextUtils.isEmpty(title)) {
            buider.setTitle(title);
        }
        if (!TextUtils.isEmpty(content)) {
            buider.setMessage(content);
        }
        if (!TextUtils.isEmpty(negative)) {

            buider.setmNegtiveColor(negativeColor);
            buider.setNegative(negative);
        }
        if (!TextUtils.isEmpty(positive)) {
            buider.setPositive(positive);
        }
        buider.setOnCustomAlertDialogClickListener(listener);
        return buider.create();
    }

    /**
     * 弹出框  底部可自定义  不要哪个就不传哪个  比如不要positive  positive就传Null
     * 左边灰色,右边橙色
     *
     * @param mContext
     * @param content
     * @param negative
     * @param positive
     * @param listener
     * @return
     */
    public static OutProjectDialog createOutProjectDialog(Context mContext, String content, String negative, String positive, OnOutProjectDialogClickListener listener) {
        OutProjectDialog.Builder buider = new OutProjectDialog.Builder(mContext);
        if (!TextUtils.isEmpty(content)) {
            buider.setMessage(content);
        }
        if (!TextUtils.isEmpty(negative)) {
            buider.setNegative(negative);
        }
        if (!TextUtils.isEmpty(positive)) {
            buider.setPositive(positive);
        }
        buider.setOnCustomAlertDialogClickListener(listener);
        return buider.create();
    }

}
